import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)
const persistence = localStorage.getItem('persistence') || '{}'
export default new Vuex.Store({
  state: {
    // 接收用户名和token
    persistence: JSON.parse(persistence)
  },
  getters: {
    // 计算属性，给state属性的里的值赋值
    getPersistence (state) {
      return state.persistence
    }
  },
  mutations: {
    // 存储用户名和token
    setPersistence (state, obj) {
      localStorage.setItem('persistence', JSON.stringify(obj))
      state.persistence = { ...state.persistence, ...obj }
    },
    // 退出登录清空信息
    clean (state) {
      state.persistence = {}
    }
  },
  actions: {
  },
  modules: {
  }
})
